//
//  XMGLoginViewController.m
//  BuDeJie19
//
//  Created by hjj on 2016/12/3.
//  Copyright © 2016年 hjjuny. All rights reserved.
//
#import "XMGLoginViewController.h"
#import "XMGLoginRegisterView.h"
/*
    复杂界面
    1.划分层次结构，按业务逻辑划分
    2. 3层，每一个结构对应一个占位视图
    3. 一个结构一个结构
 */

// 越复杂的界面 越封装

@interface XMGLoginViewController ()
@property (weak, nonatomic) IBOutlet UIView *middleView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leadingCons;

@end

@implementation XMGLoginViewController

- (IBAction)dismiss:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)clickRegister:(UIButton *)sender {
    sender.selected = !sender.selected;
    
    // 移动中间View
    _leadingCons.constant = _leadingCons.constant==0?-XMGScreenW:0;
    
    [UIView animateWithDuration:0.25 animations:^{
        [self.view layoutIfNeeded];
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    /*
        xib使用注意点
        1.一个控件从xib加载，需要去设置尺寸？默认跟xib尺寸一样
     
        2.一个控件从xib加载，需要去再次确定尺寸和位置?
     
        3.在viewDidLoad中，去设置尺寸，参考为屏幕不会有问题，参考控制器View的子控件
        3.1 viewDidLoad这个时候，还不会执行约束
        3.2 viewDidLayoutSubviews
     
     */
    
    // 创建登录View
    XMGLoginRegisterView *loginView = [XMGLoginRegisterView loginView];
    [_middleView addSubview:loginView];
    
    // 创建注册View
    XMGLoginRegisterView *registerView = [XMGLoginRegisterView registerView];
    [_middleView addSubview:registerView];
}

// 计算好所有子控件的位置完成的时候调用
// 执行完约束
- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    _middleView.subviews[0].frame = CGRectMake(0, 0, _middleView.xmg_width * 0.5, _middleView.xmg_height);
    
    _middleView.subviews[1].frame = CGRectMake(_middleView.xmg_width * 0.5, 0, _middleView.xmg_width * 0.5, _middleView.xmg_height);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
